package mymac.com.app;

import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements DialogInterface.OnClickListener {

    private SharedPreferencesUtil mPreferencesUtil;
    private String[] mLanguage = new String[]{"简体中文","English"};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mPreferencesUtil = SharedPreferencesUtil.getInstance(this);
        /**
         * 如果第一次进入app，弹出语言选择框让用户选择当前语言
         */
        String isFirstOpen = mPreferencesUtil.getSP("isFirstOpen");
        if (isFirstOpen.equals("")){
            ShowDialog();
            mPreferencesUtil.putSP("isFirstOpen","0");
        } else {
            Toast.makeText(this, "您上一次已选择语言,请点击下一步", Toast.LENGTH_SHORT).show();
        }
    }

    private void ShowDialog(){
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("请选择语言");
        builder.setItems(mLanguage, this);
        builder.setNegativeButton("Cancel",null);
        builder.show();
    }

    @Override
    public void onClick(DialogInterface dialog, int which) {
        Toast.makeText(this, "您已选择" + mLanguage[which], Toast.LENGTH_SHORT).show();
    }
}
